class Asset < Remote
  
  class << self
    def root
      find(:all, :from => :root)
    end
    
    def search(query, with_content = true)
      ss = "/assets/search/#{query}"
      ss += "?with_content=false" unless with_content
      # Default is true
      find(:all, :from => ss)
    end
  end
  
  def folder
    return unless folder?
    Folder.find(folder_id)
  end
  
  def folder?
    self.folder_id? && self.folder_id.to_i != 0
  end
  
  def email(to, subject, msg)
    self.post(:email, :to => to, :subject => subject, :msg => msg)
  end
  
  def thumbnail_url
    return "/assets/#{id}/preview"
  end
  
  def is_image?
    ['.jpg', '.gif', '.png', '.bmp', '.tga', '.tif', '.tiff','.xbm', '.ppm', '.p'].include?(self.ext)
  end
  
  def is_pdf?
    self.ext == '.pdf'
  end
  
  def is_swf?
    self.ext == '.swf'
  end
  
  def file_data
    get_raw(:download)
  end
  
end